]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
cleanup: Use optional chaining and ?? operator
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 12 Aug 2020 18:59:01 +0000 (20:59 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 2 Dec 2020 15:10:29 +0000 (15:10 +0000)
Those operators have been supported since gjs switched to mozjs78
last cycle. While not ground-breaking, using it makes for a nice
cleanup here and there.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1517>

18 files changed:
js/ui/altTab.js
js/ui/appDisplay.js
js/ui/components/automountManager.js
js/ui/components/networkAgent.js
js/ui/endSessionDialog.js
js/ui/environment.js
js/ui/inhibitShortcutsDialog.js
js/ui/notificationDaemon.js
js/ui/padOsd.js
js/ui/panel.js
js/ui/panelMenu.js
js/ui/popupMenu.js
js/ui/search.js
js/ui/shellDBus.js
js/ui/windowManager.js
js/ui/windowPreview.js
js/ui/workspace.js
js/ui/xdndHandler.js

index 5332d3b7c4a42711d3a4c5ef90d9b1a69f07090c..3ecadad86861fb02905784b14343548c85657a10 100644 (file)
@@ -427,8 +427,7 @@ class CyclerHighlight extends St.Widget {
         if (this._clone.source)
             this._clone.source.sync_visibility();
 
-        let windowActor = this._window
-            ? this._window.get_compositor_private() : null;
+        const windowActor = this._window?.get_compositor_private();
 
         if (windowActor)
             windowActor.hide();
@@ -532,7 +531,7 @@ class GroupCyclerPopup extends CyclerPopup {
 
     _getWindows() {
         let app = Shell.WindowTracker.get_default().focus_app;
-        let appWindows = app ? app.get_windows() : [];
+        let appWindows = app?.get_windows() ?? [];
 
         if (this._settings.get_boolean('current-workspace-only')) {
             const workspaceManager = global.workspace_manager;
index 1cca533c70d32b706fd3cf36c830ca346dc4982a..ac92d2fd9da4ecd96e649404ac350f972ec831bf 100644 (file)
@@ -972,7 +972,7 @@ class AppDisplay extends BaseAppView {
         this._switcherooProxy = global.get_switcheroo_control();
         if (this._switcherooProxy) {
             let prop = this._switcherooProxy.get_cached_property('HasDualGpu');
-            discreteGpuAvailable = prop ? prop.unpack() : false;
+            discreteGpuAvailable = prop?.unpack() ?? false;
         } else {
             discreteGpuAvailable = false;
         }
index b83bd22c6a643331a87a79a491c0bd841e6b2acd..e50ae8e1d56f48d2234cc94b35f15b977c373542 100644 (file)
@@ -176,7 +176,7 @@ var AutomountManager = class {
         if (allowAutorun)
             this._allowAutorun(volume);
 
-        let mountOp = operation ? operation.mountOp : null;
+        const mountOp = operation?.mountOp ?? null;
         this._activeOperations.set(volume, operation);
 
         volume.mount(0, mountOp, null,
@@ -226,7 +226,7 @@ var AutomountManager = class {
 
     _reaskPassword(volume) {
         let prevOperation = this._activeOperations.get(volume);
-        let existingDialog = prevOperation ? prevOperation.borrowDialog() : null;
+        const existingDialog = prevOperation?.borrowDialog();
         let operation =
             new ShellMountOperation.ShellMountOperation(volume,
                                                         { existingDialog });
index 29565d214f22b08581369a9c767e8aaca3004526..4367a2f2a042156234bbf5a4e67e0ef32a4250e9 100644 (file)
@@ -793,7 +793,7 @@ var NetworkAgent = class {
         }
 
         const prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode');
-        const trimmedProp = prop ? prop.trim().toLowerCase() : '';
+        const trimmedProp = prop?.trim().toLowerCase() ?? '';
 
         return {
             fileName,
index ebf4f4d8162c1ff19d87e3c10eced751619cf7f3..053ae8cce0e7f0a130d6888d54417707f41a0040 100644 (file)
@@ -676,8 +676,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
                 let userAvatar = new UserWidget.Avatar(session.user, { iconSize: _ITEM_ICON_SIZE });
                 userAvatar.update();
 
-                userName = session.user.get_real_name()
-                    ? session.user.get_real_name() : session.username;
+                userName = session.user.get_real_name() ?? session.username;
 
                 let userLabelText;
                 if (session.remote)
index e777d653ad281488bdcceae51b0ebfedea450c25..fa3d490a58f8419556a6f6034b9f90a86a6891e1 100644 (file)
@@ -364,7 +364,7 @@ function init() {
             this.getHours(),
             this.getMinutes(),
             this.getSeconds());
-        return dt ? dt.format(format) : '';
+        return dt?.format(format) ?? '';
     };
 
     let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
index d16c55abdb829a1d760eb3a6476d8562dac61eb2..c59544eaf915381a9785dd5183d5727faccb41f5 100644 (file)
@@ -73,7 +73,7 @@ var InhibitShortcutsDialog = GObject.registerClass({
     }
 
     _buildLayout() {
-        let name = this._app ? this._app.get_name() : this._window.title;
+        const name = this._app?.get_name() ?? this._window.title;
 
         let content = new Dialog.MessageDialogContent({
             title: _('Allow inhibiting shortcuts'),
index 3c8e90b1e0cccb4ce5f41cb3c880b64c71d970fb..38f81c3814ecfed22b858f881c8b8dc362823fd0 100644 (file)
@@ -124,7 +124,7 @@ var FdoNotificationDaemon = class FdoNotificationDaemon {
             return source;
         }
 
-        let appId = ndata ? ndata.hints['desktop-entry'] || null : null;
+        const appId = ndata?.hints['desktop-entry'];
         source = new FdoNotificationDaemonSource(title, pid, sender, appId);
 
         this._sources.push(source);
@@ -528,10 +528,10 @@ class GtkNotificationDaemonNotification extends MessageTray.Notification {
             });
         }
 
-        this._defaultAction = defaultAction ? defaultAction.unpack() : null;
+        this._defaultAction = defaultAction?.unpack();
         this._defaultActionTarget = defaultActionTarget;
 
-        this.update(title.unpack(), body ? body.unpack() : null,
+        this.update(title.unpack(), body?.unpack(),
                     { gicon: gicon ? Gio.icon_deserialize(gicon) : null,
                       datetime: time ? GLib.DateTime.new_from_unix_local(time.unpack()) : null });
     }
index 110962259d77544924ed39ec02a7af66cd4307fa..817770a4bb977212172df8b1bf56cf3f71d1a4d4 100644 (file)
@@ -770,7 +770,7 @@ var PadOsd = GObject.registerClass({
 
     _getActionText(type, number) {
         let str = global.display.get_pad_action_label(this.padDevice, type, number);
-        return str ? str : _("None");
+        return str ?? _('None');
     }
 
     _updateActionLabels() {
@@ -887,7 +887,7 @@ var PadOsd = GObject.registerClass({
             if (this._followUpActionEdition(str))
                 return;
 
-            this._padDiagram.stopEdition(false, str ? str : _("None"));
+            this._padDiagram.stopEdition(false, str ?? _('None'));
             this._editedAction = null;
         }
 
index 272368a4b076a9e25b3b6fdad8a18f18c15d53a2..31b88f7fdd6448fc332088323fd3d71ae154947b 100644 (file)
@@ -143,8 +143,8 @@ class AppMenu extends PopupMenu.PopupMenu {
 
         this._updateWindowsSection();
 
-        let appInfo = app ? app.app_info : null;
-        let actions = appInfo ? appInfo.list_actions() : [];
+        const appInfo = app?.app_info;
+        const actions = appInfo?.list_actions() ?? [];
 
         this._actionSection.removeAll();
         actions.forEach(action => {
index 81d34490bd654c27ab46886455f51bb912561898..0c2478f8db96a3e22396b94377231095bbe936ee 100644 (file)
@@ -96,11 +96,13 @@ var Button = GObject.registerClass({
     Signals: { 'menu-set': {} },
 }, class PanelMenuButton extends ButtonBox {
     _init(menuAlignment, nameText, dontCreateMenu) {
-        super._init({ reactive: true,
-                      can_focus: true,
-                      track_hover: true,
-                      accessible_name: nameText ? nameText : "",
-                      accessible_role: Atk.Role.MENU });
+        super._init({
+            reactive: true,
+            can_focus: true,
+            track_hover: true,
+            accessible_name: nameText ?? '',
+            accessible_role: Atk.Role.MENU,
+        });
 
         if (dontCreateMenu)
             this.menu = new PopupMenu.PopupDummyMenu(this);
index a618f8fb48efd421b35a4eeb9884be562c98a9a8..11528560d41e443a0ded781301fd06a36cabc513 100644 (file)
@@ -226,7 +226,7 @@ var PopupBaseMenuItem = GObject.registerClass({
     }
 
     getSensitive() {
-        let parentSensitive = this._parent ? this._parent.sensitive : true;
+        const parentSensitive = this._parent?.sensitive ?? true;
         return this._activatable && this._sensitive && parentSensitive;
     }
 
@@ -504,7 +504,7 @@ var PopupMenuBase = class {
     }
 
     getSensitive() {
-        let parentSensitive = this._parent ? this._parent.sensitive : true;
+        const parentSensitive = this._parent?.sensitive ?? true;
         return this._sensitive && parentSensitive;
     }
 
index dd76735cec35f4045333c8e1d42c7512cd2808e4..de13d6e0141731eee352c78f4edbc83fda366ca6 100644 (file)
@@ -873,7 +873,7 @@ var SearchResultsView = GObject.registerClass({
             return;
         }
 
-        let from = this._defaultResult ? this._defaultResult : null;
+        const from = this._defaultResult ?? null;
         this.navigate_focus(from, direction, false);
     }
 
index bac9caa095e57454972714977b088d1ddad2d5c2..f7b542b2909df6b8fab9e8a5b1af33c2abc73796 100644 (file)
@@ -160,11 +160,12 @@ var GnomeShell = class {
         if (deviceNode)
             params['device-node'] = GLib.Variant.new('s', deviceNode);
 
-        connection.emit_signal(destination,
-                               this._dbusImpl.get_object_path(),
-                               info ? info.name : null,
-                               'AcceleratorActivated',
-                               GLib.Variant.new('(ua{sv})', [action, params]));
+        connection.emit_signal(
+            destination,
+            this._dbusImpl.get_object_path(),
+            info?.name ?? null,
+            'AcceleratorActivated',
+            GLib.Variant.new('(ua{sv})', [action, params]));
     }
 
     _grabAcceleratorForSender(accelerator, modeFlags, grabFlags, sender) {
index afe45037aac6dd7c1de5826d469391b1a44eb0fe..1b90c3b7daea3966f21ccc337554903594da94c9 100644 (file)
@@ -891,7 +891,7 @@ var WindowManager = class {
             // FIXME: Fix num buttons
             for (let i = 0; i < 50; i++) {
                 let str = display.get_pad_action_label(pad, Meta.PadActionType.BUTTON, i);
-                labels.push(str ? str : '');
+                labels.push(str ?? '');
             }
 
             if (this._gsdWacomProxy) {
index d379703dd8e536f02bfac289f65d2f86800d5e45..23a353ef5bff5b5e93b029298c9750999ee4e836 100644 (file)
@@ -34,7 +34,7 @@ var WindowPreviewLayout = GObject.registerClass({
 
         for (const windowInfo of this._windows.values()) {
             const frame = windowInfo.metaWindow.get_frame_rect();
-            frameRect = frameRect ? frameRect.union(frame) : frame;
+            frameRect = frameRect?.union(frame) ?? frame;
         }
 
         if (!frameRect)
index ab49e64123c6744682c00f09ddd0a400edfb0235..511ef5def3926884ebdc257515c277ecd9a33d1c 100644 (file)
@@ -1291,9 +1291,7 @@ class Workspace extends St.Widget {
     }
 
     _onCloneSelected(clone, time) {
-        let wsIndex;
-        if (this.metaWorkspace)
-            wsIndex = this.metaWorkspace.index();
+        const wsIndex = this.metaWorkspace?.index();
         Main.activateWindow(clone.metaWindow, time, wsIndex);
     }
 
index 13d012dec135f4c91f80aa99321128104f6f87a2..95549f3dbb33fab38dd0e12063de6195fff6aacc 100644 (file)
@@ -86,7 +86,7 @@ var XdndHandler = class {
         let dragEvent = {
             x,
             y,
-            dragActor: this._cursorWindowClone ? this._cursorWindowClone : this._dummy,
+            dragActor: this._cursorWindowClone ?? this._dummy,
             source: this,
             targetActor: pickedActor,
         };